home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / lspd05_1.zip / DEMO.C < prev    next >
Text File  |  1991-10-21  |  29KB  |  1,006 lines

  1. /***
  2.  ***  Light Speed Graphics Programming Library
  3.  ***
  4.  ***  Simple demonstration program
  5.  ***
  6.  ***  Compiled under Turbo C v2.01 - modifications needed for
  7.  ***  other compilers.
  8.  ***/
  9.  
  10. /* The Light Speed Header File */
  11. #include "lspeed.h"
  12.  
  13. /* Memory allocation header file */
  14. #include <alloc.h>
  15.  
  16. /* Time functions */
  17. #include <dos.h>
  18.  
  19. /* Random numbers */
  20. #include <stdlib.h>
  21.  
  22. /* Closing text */
  23. #include <conio.h>
  24.  
  25. /* The font name variables */
  26. char *fontstyles[] = {
  27.        "Broad Text",         "Computer Text",
  28.        "Plasma Display",     "EGA Small Font",
  29.        "EGA Standard",       "Tall Text",
  30.        "Script Flow",        "Nice Font",
  31.        "Crisp Character",    "Old English",
  32.        "Plain Text",         "Italic Font"       };
  33.  
  34. /* Function declarations */
  35. void title(void);
  36. void fonts(void);
  37. void demonstrate_font(int font);
  38. void images(void);
  39. void primitives(void);
  40. void demo_line(void);
  41. void demo_triangle(void);
  42. void demo_ftriangle(void);
  43. void demo_rectangle(void);
  44. void demo_circle(void);
  45. void putcircle(int xloc, int yloc, int radius, int colour);
  46. void demo_fcircle(void);
  47. void demo_ellipse(void);
  48. void putellipse(int xloc, int yloc, int radius1, int radius2, int colour);
  49. void demo_fellipse(void);
  50. void demo_pixels(void);
  51. void demo_polygon(void);
  52.  
  53. /* Main function */
  54. main()
  55. {
  56.    /* Setup graphics mode */
  57.    set640x350();
  58.  
  59.    /* Pass control over to each of the functions in turn... */
  60.  
  61.    /* Title screen */
  62.    title();
  63.  
  64.    /* Font styles */
  65.    fonts();
  66.  
  67.    /* Image manipulation system */
  68.    images();
  69.  
  70.    /* Demonstrate some of the primitives */
  71.    primitives();
  72.  
  73.    /* In closing... */
  74.    set80x25();
  75.    cprintf("Well, you've seen demos of just SOME of the Light Speed functions...\n\r");
  76.    cprintf("Now, you can use that power in your own applications!!!\n\r");
  77.    cprintf("Get stuck into it!!\n\r");
  78.    cprintf("\n\rOh yeah - register and receive the benefits - do it now!\n\r");
  79. }
  80.  
  81. /* Draw up the title screen */
  82. void title(void)
  83. {
  84.    /* Variables */
  85.    struct time current, old;
  86.  
  87.    /* Set for hidden page load */
  88.    ega_setapage(2);
  89.    ega_setvpage(1);
  90.  
  91.    /* Load in the 'LYONWARE' screen image */
  92.    ega_restore_screen_byte("logo.scr");
  93.  
  94.    /* Show the screen */
  95.    ega_setvpage(2);
  96.  
  97.    /* Load in the 'LIGHT SPEED' screen image */
  98.    ega_setapage(1);
  99.    ega_restore_screen_byte("lspd.scr");
  100.    ega_setapage(2);
  101.    ega_filledrectangle(0,0,639,349,15);
  102.    ega_setvpage(1);
  103.  
  104.    /* Wait for either time or keypress */
  105.    gettime(&old);
  106.    while (!kbhit())
  107.       {
  108.       gettime(¤t);
  109.       if (current.ti_sec>old.ti_sec+4)
  110.          break;
  111.       }
  112.    if (kbhit())        /* Get the key if there is one */
  113.       getxch();
  114. }
  115.  
  116. /* Font style demonstrations */
  117. void fonts(void)
  118. {
  119.    /* Variables */
  120.    int loop;
  121.  
  122.    /* Clear the screen */
  123.    set640x350();
  124.  
  125.    /* Register all fonts */
  126.    registerbroadfont();
  127.    registercomputerfont();
  128.    registertallfont();
  129.    registersmallfont();
  130.    registerscriptfont();
  131.    registerplasmafont();
  132.    registerplainfont();
  133.    registeroldenglishfont();
  134.    registernicefont();
  135.    registeritalicfont();
  136.    registerstandardfont();
  137.    registercrispfont();
  138.  
  139.    /* What we are doing */
  140.    ega_writetext(10, 10, LS_WHITE, LS_BLACK, NICE_FONT,
  141.                  "First up, is the flexible font system!");
  142.    ega_writetext(10, 25, LS_WHITE, LS_BLACK, NICE_FONT,
  143.                  "All 12 of the available fonts will be demonstrated!");
  144.    ega_writetext(10, 50, LS_WHITE, LS_BLACK, NICE_FONT,
  145.                  "Press a key to proceed to the demo...");
  146.    getxch();
  147.  
  148.    /* Loop through all twelve fonts */
  149.    for (loop=1; loop<=12; loop++)
  150.       demonstrate_font(loop);
  151. }
  152.  
  153. /* DEMONSTRATE_FONT - called with the value of the font to use, */
  154. /*                    this function will provide several        */
  155. /*                    graphics mode ouput tests.                */
  156. void demonstrate_font(font)
  157. int font;
  158. {
  159.    /* Variables */
  160.    int foreloop, backloop;
  161.  
  162.    /* Clear the graphics screen */
  163.    ega_clearpage();
  164.  
  165.    /* Tell the user the font we are displaying */
  166.    ega_formattext(10, 10, LS_YELLOW, LS_BLACK, STANDARD_FONT,
  167.                   "Demonstrating %s!", fontstyles[font-1]);
  168.  
  169.    /* Print out the standard alphabet in the text style */
  170.    ega_writetext(20, 30, LS_WHITE, LS_BLACK, font,
  171.                  "The standard character set:");
  172.    ega_formattext(25, 30+ega_fontheight(font), LS_CYAN, LS_BLACK, font,
  173.                   " !%c#$%&'()*+,-./0123456789:;<=>?@", 34);
  174.    ega_writetext(25, 30+ega_fontheight(font)*2, LS_CYAN, LS_BLACK, font,
  175.                  "ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`");
  176.    ega_writetext(25, 30+ega_fontheight(font)*3, LS_CYAN, LS_BLACK, font,
  177.                  "abcdefghijklmnopqrstuvwxyz{|}~");
  178.  
  179.    /* Tell a bit more about the text system */
  180.    ega_writetext(15, 120, LS_YELLOW, LS_BLACK, font,
  181.                  "The above is only a demonstration of the font...");
  182.    ega_writetext(15, 120+ega_fontheight(font), LS_YELLOW, LS_BLACK, font,
  183.                  "The real power lies in foreground/background colours!");
  184.    for (foreloop=0; foreloop<=15; foreloop++)
  185.       for (backloop=0; backloop<=7; backloop++)
  186.          ega_writetext(30+foreloop*32, 160+backloop*ega_fontheight(font),
  187.                        foreloop, backloop, font, " WOW ");
  188.  
  189.    /* Write a message and wait for the next keypress */
  190.    ega_writetext(15, 320, LS_WHITE, LS_BLUE, STANDARD_FONT,
  191.                  "  Press any key to continue...  ");
  192.    getxch();
  193. }
  194.  
  195. /* Demonstrate the image manipulation routines */
  196. void images(void)
  197. {
  198.    /* Variables */
  199.    int loop, xloc, yloc;
  200.    unsigned char image;
  201.    unsigned int key;
  202.    char far *heli1,  far *heli2,  far *heli3,  far *heli4;
  203.  
  204.    /* Set graphics */
  205.    set320x200();
  206.  
  207.    /* Write a 'wait' message */
  208.    ega_writetext(10, 10, LS_YELLOW, LS_BLACK, STANDARD_FONT,
  209.                  "Next up is the powerful image system!");
  210.    ega_writetext(10, 20, LS_YELLOW, LS_BLACK, STANDARD_FONT,
  211.                  "These graphics are from part of a game");
  212.    ega_writetext(10, 30, LS_YELLOW, LS_BLACK, STANDARD_FONT,
  213.                  "I am working on! (Using Light Speed)");
  214.    ega_writetext(10, 45, LS_YELLOW, LS_BLACK, STANDARD_FONT,
  215.                  "Please wait, loading data...");
  216.  
  217.    /* Allocate data for the images */
  218.    heli1=farmalloc(ega_imagesize(0,0,46,40));
  219.    heli2=farmalloc(ega_imagesize(0,0,46,40));
  220.    heli3=farmalloc(ega_imagesize(0,0,46,40));
  221.    heli4=farmalloc(ega_imagesize(0,0,46,40));
  222.  
  223.    /* Check for any that didn't allocate */
  224.    if (heli1==NULL || heli2==NULL || heli3==NULL || heli4==NULL)
  225.       {
  226.       /* De-allocate all images */
  227.       farfree(heli1);    farfree(heli2);
  228.       farfree(heli3);    farfree(heli4);
  229.       set80x25();
  230.       printf("Did not have enough memory to load data!\n");
  231.       exit(1);
  232.       }
  233.  
  234.    /* Load into the hidden page */
  235.    ega_setapage(2);
  236.    if (ega_restore_area_byte("heli.img",0,0,187,37,0,2)==-2)
  237.       {
  238.       farfree(heli1);    farfree(heli2);
  239.       farfree(heli3);    farfree(heli4);
  240.       set80x25();
  241.       printf("Could not find 'HELI.IMG' image file...\n");
  242.       exit(1);
  243.       }
  244.  
  245.    /* Save the images */
  246.    ega_getimage(  0, 0, 46, 40, heli1);
  247.    ega_getimage( 47, 0, 93, 40, heli2);
  248.    ega_getimage( 94, 0,140, 40, heli3);
  249.    ega_getimage(141, 0,187, 40, heli4);
  250.  
  251.    /* Enough time to read message */
  252.    ega_setapage(1);
  253.    ega_writetext(10, 45, LS_YELLOW, LS_BLACK, STANDARD_FONT,
  254.                  "Press a key to continue...  ");
  255.    getxch();
  256.  
  257.    /* Clear all pages */
  258.    set320x200();
  259.  
  260.    /* Write instructions */
  261.    ega_writetext(0, 0, LS_WHITE, LS_BLACK, STANDARD_FONT,
  262.                  "Use cursor keys to control, Esc to stop");
  263.  
  264.    /* Variables setup */
  265.    image=0;
  266.    xloc=150;
  267.    yloc=75;
  268.  
  269.    /* Loop */
  270.    loop:
  271.    if (kbhit())
  272.       key=getxch();             /* Key available */
  273.    else
  274.       key=0;                    /* No key */
  275.  
  276.    /* ESC aborts */
  277.    if (key==0x011B)
  278.       {
  279.       farfree(heli1);    farfree(heli2);
  280.       farfree(heli3);    farfree(heli4);
  281.       return;
  282.       }
  283.  
  284.    /* Test for directions */
  285.    switch (key)
  286.       {
  287.       case 0x4800 : /* UP */
  288.                     yloc--;  yloc--;
  289.                     if (yloc<10)
  290.                        yloc=10;
  291.                     break;
  292.       case 0x4900 : /* UP-RIGHT */
  293.                     yloc--;  yloc--;
  294.                     if (yloc<10)
  295.                        yloc=10;
  296.                     xloc++;  xloc++;
  297.                     if (xloc>272)
  298.                        xloc=272;
  299.                     break;
  300.       case 0x4700 : /* UP-LEFT */
  301.                     yloc--;  yloc--;
  302.                     if (yloc<10)
  303.                        yloc=10;
  304.                     xloc--;  xloc--;
  305.                     if (xloc<0)
  306.                        xloc=0;
  307.                     break;
  308.       case 0x5000 : /* DOWN */
  309.                     yloc++;  yloc++;
  310.                     if (yloc>161)
  311.                        yloc=161;
  312.                     break;
  313.       case 0x5100 : /* DOWN-RIGHT */
  314.                     yloc++;  yloc++;
  315.                     if (yloc>161)
  316.                        yloc=161;
  317.                     xloc++;  xloc++;
  318.                     if (xloc>272)
  319.                        xloc=272;
  320.                     break;
  321.       case 0x4F00 : /* DOWN-LEFT */
  322.                     yloc++;  yloc++;
  323.                     if (yloc>161)
  324.                        yloc=161;
  325.                     xloc--;  xloc--;
  326.                     if (xloc<0)
  327.                        xloc=0;
  328.                     break;
  329.       case 0x4D00 : /* RIGHT */
  330.                     xloc++;  xloc++;
  331.                     if (xloc>272)
  332.                        xloc=272;
  333.                     break;
  334.       case 0x4B00 : /* LEFT */
  335.                     xloc--;  xloc--;
  336.                     if (xloc<0)
  337.                        xloc=0;
  338.                     break;
  339.       }
  340.  
  341.    /* Update image */
  342.    image++;
  343.  
  344.    /* Draw correct image */
  345.    if (image<7)
  346.       ega_putimage(heli1, xloc, yloc);
  347.    else if (image<14)
  348.       ega_putimage(heli2, xloc, yloc);
  349.    else if (image<21)
  350.       ega_putimage(heli3, xloc, yloc);
  351.    else if (image<28)
  352.       ega_putimage(heli4, xloc, yloc);
  353.    else
  354.       image=0;             /* Out of range - reset */
  355.  
  356.    /* Repeat cycle */
  357.    goto loop;
  358. }
  359.  
  360. /* Demonstrate some of the grpahics primitives */
  361. void primitives(void)
  362. {
  363.    /* Set graphics mode */
  364.    set640x350();
  365.  
  366.    /* What is going to happen */
  367.    ega_writetext(10, 10, LS_WHITE, LS_BLACK, NICE_FONT,
  368.                  "The following series of demonstrations show you the flexibility of the");
  369.    ega_writetext(10, 25, LS_WHITE, LS_BLACK, NICE_FONT,
  370.                  "graphics primitives. They are all in one long sequence... Just press");
  371.    ega_writetext(10, 40, LS_WHITE, LS_BLACK, NICE_FONT,
  372.                  "a key to continue from one to the next!!!");
  373.    ega_writetext(10, 60, LS_YELLOW, LS_BLACK, NICE_FONT,
  374.                  "Press a key now to start...");
  375.    getxch();
  376.  
  377.    /* Line drawing */
  378.    demo_line();
  379.  
  380.    /* Triangle drawing */
  381.    demo_triangle();
  382.  
  383.    /* Filled triangle drawing */
  384.    demo_ftriangle();
  385.  
  386.    /* Rectangle drawing */
  387.    demo_rectangle();
  388.  
  389.    /* Circle drawing */
  390.    demo_circle();
  391.  
  392.    /* Filled circle drawing */
  393.    demo_fcircle();
  394.  
  395.    /* Ellipse drawing */
  396.    demo_ellipse();
  397.  
  398.    /* Filled ellipse drawing */
  399.    demo_fellipse();
  400.  
  401.    /* Pixel plotting */
  402.    demo_pixels();
  403.  
  404.    /* Polygon drawing */
  405.    demo_polygon();
  406. }
  407.  
  408. /* Line drawing demonstration */
  409. void demo_line(void)
  410. {
  411.    /* Variables */
  412.    int lines[4][32], left_x_inc, right_x_inc, up_y_inc, down_y_inc;
  413.    unsigned char curline;
  414.  
  415.    /* Set the graphics mode */
  416.    set640x350();
  417.  
  418.    /* Seed the random numbers, set variables */
  419.    randomize();
  420.    left_x_inc=-2;
  421.    right_x_inc=2;
  422.    up_y_inc=2;
  423.    down_y_inc=2;
  424.  
  425.    /* Print the demonstration message */
  426.    ega_writetext(132, 335, LS_YELLOW, LS_BLUE, NICE_FONT,
  427.                  " Line drawing demo! Press a key to continue... ");
  428.  
  429.    /* Set up some lines */
  430.    lines[0][0] = 320;
  431.    lines[1][0] = 170;
  432.    lines[2][0] = 320;
  433.    lines[3][0] = 170;
  434.    for (curline=1; curline<32; curline++)
  435.       {
  436.       lines[0][curline] = lines[0][curline-1]+left_x_inc;
  437.       lines[1][curline] = lines[1][curline-1]+up_y_inc;
  438.       lines[2][curline] = lines[2][curline-1]+right_x_inc;
  439.       lines[3][curline] = lines[3][curline-1]+down_y_inc;
  440.       }
  441.  
  442.    /* Draw the lines */
  443.    for (curline=0; curline<32; curline++)
  444.       ega_putline(lines[0][curline], lines[1][curline],
  445.                   lines[2][curline], lines[3][curline], curline);
  446.    curline=31;
  447.  
  448.    /* While there is no key... */
  449.    while (!kbhit())
  450.       {
  451.       curline++;
  452.  
  453.       /* Erase the last line */
  454.       ega_putline(lines[0][curline&31], lines[1][curline&31],
  455.                   lines[2][curline&31], lines[3][curline&31], 0);
  456.  
  457.       /* Increment the first point */
  458.       lines[0][curline&31] = lines[0][(curline-1)&31]+left_x_inc;
  459.       if (lines[0][curline&31]<0)            /* Out of range? */
  460.          {
  461.          left_x_inc=random(11)+3;
  462.          lines[0][curline&31]=0;
  463.          }
  464.       if (lines[0][curline&31]>639)          /* Out of range? */
  465.          {
  466.          left_x_inc=-10+random(11)-3;
  467.          lines[0][curline&31]=639;
  468.          }
  469.  
  470.       /* Increment the second point */
  471.       lines[1][curline&31] = lines[1][(curline-1)&31]+up_y_inc;
  472.       if (lines[1][curline&31]<0)            /* Out of range? */
  473.          {
  474.          up_y_inc=random(11)+3;
  475.          lines[1][curline&31]=0;
  476.          }
  477.       if (lines[1][curline&31]>334)          /* Out of range? */
  478.          {
  479.          up_y_inc=-10+random(11)-3;
  480.          lines[1][curline&31]=334;
  481.          }
  482.  
  483.       /* Increment the third point */
  484.       lines[2][curline&31] = lines[2][(curline-1)&31]+right_x_inc;
  485.       if (lines[2][curline&31]<0)            /* Out of range? */
  486.          {
  487.          right_x_inc=random(11)+3;
  488.          lines[2][curline&31]=0;
  489.          }
  490.       if (lines[2][curline&31]>639)          /* Out of range? */
  491.          {
  492.          right_x_inc=-10+random(11)-3;
  493.          lines[2][curline&31]=639;
  494.          }
  495.  
  496.       /* Increment the last point */
  497.       lines[3][curline&31] = lines[3][(curline-1)&31]+down_y_inc;
  498.       if (lines[3][curline&31]<0)            /* Out of range? */
  499.          {
  500.          down_y_inc=random(11)+3;
  501.          lines[3][curline&31]=0;
  502.          }
  503.       if (lines[3][curline&31]>334)          /* Out of range? */
  504.          {
  505.          down_y_inc=-10+random(11)-3;
  506.          lines[3][curline&31]=334;
  507.          }
  508.  
  509.       /* Draw the newly updated line */
  510.       ega_putline(lines[0][curline&31], lines[1][curline&31],
  511.                   lines[2][curline&31], lines[3][curline&31], curline);
  512.  
  513.       /* Small microprocessor delay */
  514.       delay(5);
  515.       }
  516.  
  517.    /* Get the key */
  518.    getxch();
  519. }
  520.  
  521. /* Triangle drawing demonstration */
  522. void demo_triangle(void)
  523. {
  524.    /* Variables */
  525.    int lines[6][16], first_x_inc, second_x_inc, first_y_inc;
  526.    int second_y_inc, third_x_inc, third_y_inc;
  527.    unsigned char curline;
  528.  
  529.    /* Set the graphics mode */
  530.    set640x350();
  531.  
  532.    /* Seed the random numbers, set variables */
  533.    randomize();
  534.    first_x_inc=0;
  535.    second_x_inc=2;
  536.    third_x_inc=-2;
  537.    first_y_inc=-2;
  538.    second_y_inc=2;
  539.    third_y_inc=2;
  540.  
  541.    /* Print the demonstration message */
  542.    ega_writetext(116, 335, LS_YELLOW, LS_BLUE, NICE_FONT,
  543.                  " Triangle drawing demo! Press a key to continue... ");
  544.  
  545.    /* Set first some lines */
  546.    lines[0][0] = 320;
  547.    lines[1][0] = 170;
  548.    lines[2][0] = 320;
  549.    lines[3][0] = 170;
  550.    lines[4][0] = 320;
  551.    lines[5][0] = 170;
  552.  
  553.    for (curline=1; curline<16; curline++)
  554.    {
  555.       lines[0][curline] = lines[0][curline-1]+first_x_inc;
  556.       lines[1][curline] = lines[1][curline-1]+first_y_inc;
  557.       lines[2][curline] = lines[2][curline-1]+second_x_inc;
  558.       lines[3][curline] = lines[3][curline-1]+second_y_inc;
  559.       lines[4][curline] = lines[4][curline-1]+third_x_inc;
  560.       lines[5][curline] = lines[5][curline-1]+third_y_inc;
  561.    }
  562.  
  563.    /* Draw the lines */
  564.    for (curline=0; curline<16; curline++)
  565.       ega_puttriangle(lines[0][curline], lines[1][curline],
  566.                       lines[2][curline], lines[3][curline],
  567.                       lines[4][curline], lines[5][curline],
  568.                       curline&15);
  569.    curline=15;
  570.  
  571.    /* While there is no key... */
  572.    while (!kbhit())
  573.       {
  574.       curline++;
  575.  
  576.       /* Erase the last triangle */
  577.       ega_puttriangle(lines[0][curline&15], lines[1][curline&15],
  578.                       lines[2][curline&15], lines[3][curline&15],
  579.                       lines[4][curline&15], lines[5][curline&15], 0);
  580.  
  581.       /* Increment the first point */
  582.       lines[0][curline&15] = lines[0][(curline-1)&15]+first_x_inc;
  583.       if (lines[0][curline&15]<0)            /* Out of range? */
  584.          {
  585.          first_x_inc=random(11)+3;
  586.          lines[0][curline&15]=0;
  587.          }
  588.       if (lines[0][curline&15]>639)          /* Out of range? */
  589.          {
  590.          first_x_inc=-10+random(11)-3;
  591.          lines[0][curline&15]=639;
  592.          }
  593.  
  594.       /* Increment the second point */
  595.       lines[1][curline&15] = lines[1][(curline-1)&15]+first_y_inc;
  596.       if (lines[1][curline&15]<0)            /* Out of range? */
  597.          {
  598.          first_y_inc=random(11)+3;
  599.          lines[1][curline&15]=0;
  600.          }
  601.       if (lines[1][curline&15]>334)          /* Out of range? */
  602.          {
  603.          first_y_inc=-10+random(11)-3;
  604.          lines[1][curline&15]=334;
  605.          }
  606.  
  607.       /* Increment the third point */
  608.       lines[2][curline&15] = lines[2][(curline-1)&15]+second_x_inc;
  609.       if (lines[2][curline&15]<0)            /* Out of range? */
  610.          {
  611.          second_x_inc=random(11)+3;
  612.          lines[2][curline&15]=0;
  613.          }
  614.       if (lines[2][curline&15]>639)          /* Out of range? */
  615.          {
  616.          second_x_inc=-10+random(11)-3;
  617.          lines[2][curline&15]=639;
  618.          }
  619.  
  620.       /* Increment the fourth point */
  621.       lines[3][curline&15] = lines[3][(curline-1)&15]+second_y_inc;
  622.       if (lines[3][curline&15]<0)            /* Out of range? */
  623.          {
  624.          second_y_inc=random(11)+3;
  625.          lines[3][curline&15]=0;
  626.          }
  627.       if (lines[3][curline&15]>334)          /* Out of range? */
  628.          {
  629.          second_y_inc=-10+random(11)-3;
  630.          lines[3][curline&15]=334;
  631.          }
  632.  
  633.       /* Increment the fifth point */
  634.       lines[4][curline&15] = lines[4][(curline-1)&15]+third_x_inc;
  635.       if (lines[4][curline&15]<0)            /* Out of range? */
  636.          {
  637.          third_x_inc=random(11)+3;
  638.          lines[4][curline&15]=0;
  639.          }
  640.       if (lines[4][curline&15]>639)          /* Out of range? */
  641.          {
  642.          third_x_inc=-10+random(11)-3;
  643.          lines[4][curline&15]=639;
  644.          }
  645.  
  646.       /* Increment the last point */
  647.       lines[5][curline&15] = lines[5][(curline-1)&15]+third_y_inc;
  648.       if (lines[5][curline&15]<0)            /* Out of range? */
  649.          {
  650.          third_y_inc=random(11)+3;
  651.          lines[5][curline&15]=0;
  652.          }
  653.       if (lines[5][curline&15]>334)          /* Out of range? */
  654.          {
  655.          third_y_inc=-10+random(11)-3;
  656.          lines[5][curline&15]=334;
  657.          }
  658.  
  659.       /* Draw the new triangle */
  660.       ega_puttriangle(lines[0][curline&15], lines[1][curline&15],
  661.                       lines[2][curline&15], lines[3][curline&15],
  662.                       lines[4][curline&15], lines[5][curline&15],
  663.                       curline);
  664.  
  665.       delay(5);
  666.       }
  667.  
  668.    /* Get the key */
  669.    getxch();
  670. }
  671.  
  672. /* Filled triangle drawing */
  673. void demo_ftriangle(void)
  674. {
  675.    /* Set the graphics mode */
  676.    set640x350();
  677.  
  678.    /* Seed the random numbers */
  679.    randomize();
  680.  
  681.    /* Print the demonstration message */
  682.    ega_writetext(88, 335, LS_YELLOW, LS_BLUE, NICE_FONT,
  683.                  " Filled triangle drawing demo! Press a key to continue... ");
  684.  
  685.    /* While there is no key... */
  686.    while (!kbhit())
  687.       {
  688.       /* Draw a random triangle */
  689.       ega_filledtriangle(random(640), random(335), random(640),
  690.                          random(335), random(640), random(335),
  691.                          random(16));
  692.       }
  693.  
  694.    /* Get the key */
  695.    getxch();
  696. }
  697.  
  698. /* Rectangle drawing demo */
  699. void demo_rectangle(void)
  700. {
  701.    /* Variables */
  702.    int lines[4][16], left_x_inc, right_x_inc, up_y_inc, down_y_inc;
  703.    unsigned char curline;
  704.  
  705.    /* Set the graphics mode */
  706.    set640x350();
  707.  
  708.    /* Seed the random numbers, set variables */
  709.    randomize();
  710.    left_x_inc=-5;
  711.    right_x_inc=5;
  712.    up_y_inc=-5;
  713.    down_y_inc=5;
  714.  
  715.    /* Print the demonstration message */
  716.    ega_writetext(112, 335, LS_YELLOW, LS_BLUE, NICE_FONT,
  717.                  " Rectangle drawing demo! Press a key to continue... ");
  718.  
  719.    /* Set up some lines */
  720.    lines[0][0] = 320;
  721.    lines[1][0] = 170;
  722.    lines[2][0] = 320;
  723.    lines[3][0] = 170;
  724.    for (curline=1; curline<16; curline++)
  725.       {
  726.       lines[0][curline] = lines[0][curline-1]+left_x_inc;
  727.       lines[1][curline] = lines[1][curline-1]+up_y_inc;
  728.       lines[2][curline] = lines[2][curline-1]+right_x_inc;
  729.       lines[3][curline] = lines[3][curline-1]+down_y_inc;
  730.       }
  731.  
  732.    /* Draw the lines */
  733.    for (curline=0; curline<16; curline++)
  734.       ega_putrectangle(lines[0][curline], lines[1][curline],
  735.                        lines[2][curline], lines[3][curline], curline);
  736.    curline=15;
  737.  
  738.    /* While there is no key... */
  739.    while (!kbhit())
  740.       {
  741.       curline++;
  742.  
  743.       /* Erase the last rectangle */
  744.       ega_putrectangle(lines[0][curline&15], lines[1][curline&15],
  745.                        lines[2][curline&15], lines[3][curline&15], 0);
  746.  
  747.       /* Increment first point */
  748.       lines[0][curline&15] = lines[0][(curline-1)&15]+left_x_inc;
  749.       if (lines[0][curline&15]<0)            /* Out of range? */
  750.          {
  751.          left_x_inc=random(11)+3;
  752.          lines[0][curline&15]=0;
  753.          }
  754.       if (lines[0][curline&15]>639)          /* Out of range? */
  755.          {
  756.          left_x_inc=-10+random(11)-3;
  757.          lines[0][curline&15]=639;
  758.          }
  759.  
  760.       /* Increment the second point */
  761.       lines[1][curline&15] = lines[1][(curline-1)&15]+up_y_inc;
  762.       if (lines[1][curline&15]<0)            /* Out of range? */
  763.          {
  764.          up_y_inc=random(11)+3;
  765.          lines[1][curline&15]=0;
  766.          }
  767.       if (lines[1][curline&15]>334)          /* Out of range? */
  768.          {
  769.          up_y_inc=-10+random(11)-3;
  770.          lines[1][curline&15]=334;
  771.          }
  772.  
  773.       /* Increment the third point */
  774.       lines[2][curline&15] = lines[2][(curline-1)&15]+right_x_inc;
  775.       if (lines[2][curline&15]<0)            /* Out of range? */
  776.          {
  777.          right_x_inc=random(11)+3;
  778.          lines[2][curline&15]=0;
  779.          }
  780.       if (lines[2][curline&15]>639)          /* Out of range? */
  781.          {
  782.          right_x_inc=-10+random(11)-3;
  783.          lines[2][curline&15]=639;
  784.          }
  785.  
  786.       /* Increment the last point */
  787.       lines[3][curline&15] = lines[3][(curline-1)&15]+down_y_inc;
  788.       if (lines[3][curline&15]<0)            /* Out of range? */
  789.          {
  790.          down_y_inc=random(11)+3;
  791.          lines[3][curline&15]=0;
  792.          }
  793.       if (lines[3][curline&15]>334)          /* Out of range? */
  794.          {
  795.          down_y_inc=-10+random(11)-3;
  796.          lines[3][curline&15]=334;
  797.          }
  798.       ega_putrectangle(lines[0][curline&15], lines[1][curline&15],
  799.                        lines[2][curline&15], lines[3][curline&15], curline);
  800.  
  801.       delay(15);
  802.       }
  803.  
  804.    /* Get the key */
  805.    getxch();
  806. }
  807.  
  808. /* Circle drawing demo */
  809. void demo_circle(void)
  810. {
  811.    /* Set the graphics mode */
  812.    set640x350();
  813.  
  814.    /* Seed the random numbers */
  815.    randomize();
  816.  
  817.    /* Print the demonstration message */
  818.    ega_writetext(124, 335, LS_YELLOW, LS_BLUE, NICE_FONT,
  819.                  " Circle drawing demo! Press a key to continue... ");
  820.  
  821.    /* While there is no key... */
  822.    while (!kbhit())
  823.       {
  824.       /* Place a random circle on the screen */
  825.       putcircle(50+random(540), 50+random(235),
  826.                 random(50), random(16));
  827.       }
  828.  
  829.    /* Get the key */
  830.    getxch();
  831. }
  832.  
  833. /* Draw a circle 3 lines wide */
  834. void putcircle(xloc, yloc, radius, colour)
  835. int xloc, yloc;
  836. int radius;
  837. int colour;
  838. {
  839.    if (radius<3)
  840.       return;
  841.    ega_putcircle(xloc, yloc, radius, colour);
  842.    ega_putcircle(xloc, yloc, radius-1, colour);
  843.    ega_putcircle(xloc, yloc, radius-2, colour);
  844. }
  845.  
  846. /* Filled circles demo */
  847. void demo_fcircle(void)
  848. {
  849.    /* Set the graphics mode */
  850.    set640x350();
  851.  
  852.    /* Seed the random numbers */
  853.    randomize();
  854.  
  855.    /* Print the demonstration message */
  856.    ega_writetext(96, 335, LS_YELLOW, LS_BLUE, NICE_FONT,
  857.                  " Filled circle drawing demo! Press a key to continue... ");
  858.  
  859.    /* While there is no key... */
  860.    while (!kbhit())
  861.       {
  862.       /* Place a random circle on the screen */
  863.       ega_filledcircle(50+random(535), 50+random(235), random(50),
  864.                        random(16));
  865.       }
  866.  
  867.    /* Get the key */
  868.    getxch();
  869. }
  870.  
  871. /* Ellipse drawing demo */
  872. void demo_ellipse(void)
  873. {
  874.    /* Set the graphics mode */
  875.    set640x350();
  876.  
  877.    /* Seed the random numbers */
  878.    randomize();
  879.  
  880.    /* Print the demonstration message */
  881.    ega_writetext(120, 335, LS_YELLOW, LS_BLUE, NICE_FONT,
  882.                  " Ellipse drawing demo! Press a key to continue... ");
  883.  
  884.    /* While there is no key... */
  885.    while (!kbhit())
  886.       {
  887.       /* Place a random ellipse on the screen */
  888.       putellipse(50+random(540), 50+random(235),
  889.                  random(50), random(50), random(16));
  890.       }
  891.  
  892.    /* Get the key */
  893.    getxch();
  894. }
  895.  
  896. /* Draw an ellipse 3 lines wide */
  897. void putellipse(xloc, yloc, radius1, radius2, colour)
  898. int xloc, yloc;
  899. int radius1, radius2;
  900. int colour;
  901. {
  902.    if (radius1<3 || radius2<3)
  903.       return;
  904.    ega_putellipse(xloc, yloc, radius1, radius2, colour);
  905.    ega_putellipse(xloc, yloc, radius1-1, radius2-1, colour);
  906.    ega_putellipse(xloc, yloc, radius1-2, radius2-2, colour);
  907. }
  908.  
  909. /* Filled ellipse demo */
  910. void demo_fellipse(void)
  911. {
  912.    /* Set the graphics mode */
  913.    set640x350();
  914.  
  915.    /* Seed the random numbers */
  916.    randomize();
  917.  
  918.    /* Print the demonstration message */
  919.    ega_writetext(92, 335, LS_YELLOW, LS_BLUE, NICE_FONT,
  920.                  " Filled ellipse drawing demo! Press a key to continue... ");
  921.  
  922.    /* While there is no key... */
  923.    while (!kbhit())
  924.       {
  925.       /* Place a random ellipse on the screen */
  926.       ega_filledellipse(50+random(540), 50+random(235), random(45)+5,
  927.                         random(45)+5, random(16));
  928.       }
  929.  
  930.    /* Get the key */
  931.    getxch();
  932. }
  933.  
  934. /* Pixel plotting demo */
  935. void demo_pixels(void)
  936. {
  937.    /* Variables */
  938.    int xloc, yloc, colour;
  939.  
  940.    /* Set the graphics mode, register font */
  941.    set640x350();
  942.    registernicefont();
  943.  
  944.    /* Seed the random numbers */
  945.    randomize();
  946.  
  947.    /* Print the demonstration message */
  948.    ega_writetext(124, 335, LS_YELLOW, LS_BLUE, NICE_FONT,
  949.                  " Pixel plotting demo! Press a key to continue... ");
  950.  
  951.    /* While there is no key... */
  952.    while (!kbhit())
  953.       {
  954.       /* Place a random pixel on the screen */
  955.       xloc = random(640);
  956.       yloc = random(335);
  957.       colour = random(16);
  958.  
  959.       /* Don't update already used locations */
  960.       if (!ega_getpixel(xloc, yloc))
  961.          ega_putpixel(xloc, yloc, colour);
  962.       }
  963.  
  964.    /* Get the key */
  965.    getxch();
  966. }
  967.  
  968. /* Polygon drawing demo */
  969. void demo_polygon(void)
  970. {
  971.    /* Variables */
  972.    int locations[20][2], loop, looptop;
  973.  
  974.    /* Set the graphics mode */
  975.    set640x350();
  976.  
  977.    /* Seed the random numbers */
  978.    randomize();
  979.  
  980.    /* Print the demonstration message */
  981.    ega_writetext(120, 335, LS_YELLOW, LS_BLUE, NICE_FONT,
  982.                  " Polygon drawing demo! Press a key to continue... ");
  983.  
  984.    /* While there is no key... */
  985.    while (!kbhit())
  986.       {
  987.       /* Place a random pixel on the screen */
  988.       ega_putpoly(random(16), random(640), random(335), random(640),
  989.                   random(335), random(640), random(335), random(640),
  990.                   random(335), random(640), random(335), random(640),
  991.                   random(335), -1, -1);
  992.  
  993.       /* Small time delay */
  994.       delay(125);
  995.       }
  996.  
  997.    /* Get the key */
  998.    getxch();
  999. }
  1000.  
  1001.  
  1002.  
  1003.  
  1004.  
  1005.  
  1006.